package com.zr.service.impl;

import java.util.ArrayList;

import org.apache.taglibs.standard.tag.common.xml.JSTLXPathNamespaceContext;

import com.zr.dao.TypeDao;
import com.zr.dao.impl.TypeDaoImpl;
import com.zr.service.TypeServer;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 
 * @author lmm
 *
 */
public class TypeServerImpl implements TypeServer {

	@Override
	public void addType(String tname, int tid) {
		TypeDao td = new TypeDaoImpl();
		td.addTypeToDB(tname, tid);
	}

	@Override
	public void changeType(String tname, int tid) {
		TypeDao td = new TypeDaoImpl();
		td.changeTypeToDB(tname, tid);
	}

	@Override
	public void deleteType(int tid) {
		TypeDao td = new TypeDaoImpl();
		td.deleteTypeToDB(tid);
	}

	@Override
	public JSONArray getAllTname() {
		TypeDao td = new TypeDaoImpl();
		JSONArray json = new JSONArray();
		ArrayList<String> list = td.getAllTnameByTstate();
		for (int i = 0; i < list.size(); i++) {
			JSONObject j = new JSONObject();
			j.put("id", list.get(i));
			if(i==1){
				j.put("selected","true");
			}
			j.put("text", list.get(i));
			json.add(j);
		}
		return json;
	}
}
